﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Teigha.Core;

namespace Teigha.TD
{
	public class OdDbGraphNode : OdRxObject
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdDbGraphNode(IntPtr cPtr, bool cMemoryOwn) : base(TD_DbPINVOKE.OdDbGraphNode_SWIGUpcast(cPtr), cMemoryOwn)
		{
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdDbGraphNode obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdDbGraphNode()
		{
			this.Dispose();
		}

		public override void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							TD_DbPINVOKE.delete_OdDbGraphNode(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
			base.Dispose();
		}

		public new static OdDbGraphNode cast(OdRxObject pObj)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbGraphNode_cast(OdRxObject.getCPtr(pObj));
			OdDbGraphNode result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbGraphNode)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbGraphNode)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbGraphNode)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new static OdRxClass desc()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbGraphNode_desc(), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxClass isA()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbGraphNode_isA(this.swigCPtr), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxObject queryX(OdRxClass protocolClass)
		{
			OdRxObject result = Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbGraphNode_queryX(this.swigCPtr, OdRxClass.getCPtr(protocolClass)), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdDbGraphNode createObject()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbGraphNode_createObject();
			OdDbGraphNode result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbGraphNode)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbGraphNode)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbGraphNode)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public IntPtr data()
		{
			IntPtr result = TD_DbPINVOKE.OdDbGraphNode_data(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public void setData(IntPtr pData)
		{
			TD_DbPINVOKE.OdDbGraphNode_setData(this.swigCPtr, pData);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public int numOut()
		{
			int result = TD_DbPINVOKE.OdDbGraphNode_numOut(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public int numIn()
		{
			int result = TD_DbPINVOKE.OdDbGraphNode_numIn(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbGraphNode _in(int refIndex)
		{
			OdDbGraphNode result = (OdDbGraphNode)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbGraphNode__in(this.swigCPtr, refIndex), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbGraphNode _out(int refIndex)
		{
			OdDbGraphNode result = (OdDbGraphNode)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbGraphNode__out(this.swigCPtr, refIndex), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public void addRefTo(OdDbGraphNode pTo)
		{
			TD_DbPINVOKE.OdDbGraphNode_addRefTo(this.swigCPtr, OdDbGraphNode.getCPtr(pTo));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public void removeRefTo(OdDbGraphNode pNode)
		{
			TD_DbPINVOKE.OdDbGraphNode_removeRefTo(this.swigCPtr, OdDbGraphNode.getCPtr(pNode));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public void disconnectAll()
		{
			TD_DbPINVOKE.OdDbGraphNode_disconnectAll(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public OdDbGraph owner()
		{
			IntPtr intPtr = TD_DbPINVOKE.OdDbGraphNode_owner(this.swigCPtr);
			OdDbGraph result = (intPtr == IntPtr.Zero) ? null : new OdDbGraph(intPtr, false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool isMarkedAs(byte flags)
		{
			bool result = TD_DbPINVOKE.OdDbGraphNode_isMarkedAs(this.swigCPtr, flags);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public void markAs(byte flags)
		{
			TD_DbPINVOKE.OdDbGraphNode_markAs(this.swigCPtr, flags);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public void clear(byte flags)
		{
			TD_DbPINVOKE.OdDbGraphNode_clear(this.swigCPtr, flags);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public int numCycleOut()
		{
			int result = TD_DbPINVOKE.OdDbGraphNode_numCycleOut(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public int numCycleIn()
		{
			int result = TD_DbPINVOKE.OdDbGraphNode_numCycleIn(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbGraphNode cycleIn(int refIndex)
		{
			OdDbGraphNode result = (OdDbGraphNode)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbGraphNode_cycleIn(this.swigCPtr, refIndex), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbGraphNode cycleOut(int refIndex)
		{
			OdDbGraphNode result = (OdDbGraphNode)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbGraphNode_cycleOut(this.swigCPtr, refIndex), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbGraphNode nextCycleNode()
		{
			OdDbGraphNode result = (OdDbGraphNode)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbGraphNode_nextCycleNode(this.swigCPtr), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool isCycleNode()
		{
			bool result = TD_DbPINVOKE.OdDbGraphNode_isCycleNode(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		private object locker = new object();

		private HandleRef swigCPtr;

		[Flags]
		public enum Flags
		{
			kNone = 0,
			kVisited = 1,
			kOutsideRefed = 2,
			kSelected = 4,
			kInList = 8,
			kListAll = 14,
			kFirstLevel = 16,
			kUnresTree = 32,
			kAll = 47
		}
	}
}
